/*
 * @Author: 一路向阳 tt_sunzhenfeng@163.com
 * @Date: 2024-02-05 21:44:49
 * @LastEditors: 一路向阳 tt_sunzhenfeng@163.com
 * @LastEditTime: 2024-03-01 22:43:53
 * @FilePath: \utils_react_manager\server\app.js
 * @Description: 主入口配置
 */
const Koa =  require('koa');
// 解析post请求
const bodyParser = require('koa-bodyparser');
// 解决跨域
const cors = require('koa2-cors');
// 静态文件
const static = require('koa-static');
// uuid
const uuid = require('koa-uuid');
const onerror = require('koa-onerror')
const uuidOptions = require('./modules/uuid');
// 路由
const { login, word } = require('./router');
const {
    accessLogger,
    logger
} = require('./logger');

const app = new Koa();
onerror(app);

app.use(cors());

app.use(bodyParser());

app.use(
  static(__dirname + '/public')
);

app.use(uuid(uuidOptions));

app.use(accessLogger())

app.use(login.routes()).use(login.allowedMethods());
app.use(word.routes()).use(word.allowedMethods());

// 全局的事件监听器
app.on('error', (err) => {
  console.log('全局错误处理:', err.message, err.status, err.data)
});

app.listen(3000, () => {
    console.log('server is running at 3000');
})